import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/* Router Modules */
// 运行系统 - 基础数据
import { sysConfigRoutes } from './modules/sysConfig'
import { sysUserAndRoleRoutes } from './modules/sysUserAndRole'
import { sysEnterpriseRoutes } from './modules/sysEnterprise'
import { sysDeviceRoutes } from './modules/sysDevice'

/**
 * 固定路由
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    children: [
      {
        path: '/redirect/:path*',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index')
  },
  // {
  //   path: '/thirdAP',
  //   component: () => import('@/views/login/thirdAP')
  // },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect')
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404')
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401')
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '主页' }
      }
    ]
  },
  {
    path: '*',
    redirect: '/404'
  }
]

/**
 * 业务路由
 * businessRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const businessRoutes = [
  // 运行系统 - 基础数据
  sysConfigRoutes,
  sysUserAndRoleRoutes,
  sysEnterpriseRoutes,
  sysDeviceRoutes
]

const createRouter = () => new Router({
  mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: businessRoutes.concat(constantRoutes)
})

const router = createRouter()

export default router
